package myexchange

import org.springframework.dao.DataIntegrityViolationException

class UserController {
	def scaffold = User
	  def login = {}
  
  def authenticate = {
    def user = User.findByUserNameAndPassword(params.userName, params.password)
    if(user){
      session.user = user
      flash.message = "Hello ${user}!"
      redirect(controller:"game", action:"index")      
    }else{
      flash.message = "Sorry, ${params.userName}. Please try again."
      redirect(action:"login")
    }
  }
  
  def logout = {
    flash.message = "Goodbye ${session.user}"
    session.user = null
    redirect(controller:"game", action:"index")      
  } 
}
